package com.mrsltec.springwebandroid.controller;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.mrsltec.springwebandroid.LoginActivity;
import com.mrsltec.springwebandroid.MainSpringWeb;
import com.mrsltec.springwebandroid.R;
import com.mrsltec.springwebandroid.WebPageActivity;

/**
 * Created by zhoumingrui on 2017/3/19.
 */

public class MainSpringWebController {
    private MainSpringWeb activity;
    private Button loginButton;
    private LinearLayout homeLL,chooseLL,heavyLL,meLL;
    private RelativeLayout page2Input,page2View,page2Manage,page3Input,page3View,page3Manage;

    public MainSpringWebController(MainSpringWeb a){
        this.activity = a;
    }

    public void togglePages(int index){
        homeLL.setVisibility(View.GONE);
        chooseLL.setVisibility(View.GONE);
        heavyLL.setVisibility(View.GONE);
        meLL.setVisibility(View.GONE);
        switch (index){
            case 0:
                homeLL.setVisibility(View.VISIBLE);
                break;
            case 1:
                chooseLL.setVisibility(View.VISIBLE);
                break;
            case 2:
                heavyLL.setVisibility(View.VISIBLE);
                break;
            case 3:
                meLL.setVisibility(View.VISIBLE);
                break;
        }

    }

    public void registerEvent(){
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(activity, LoginActivity.class);
                activity.startActivity(i);
            }
        });
        page2Input.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(activity, WebPageActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url", "file:///android_asset/input.html");
                i.putExtras(bundle);
                activity.startActivity(i);
            }
        });
        page2View.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(activity, WebPageActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url", "file:///android_asset/curve.html");
                i.putExtras(bundle);
                activity.startActivity(i);
            }
        });
        page2Manage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(activity, WebPageActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url", "file:///android_asset/search.html");
                i.putExtras(bundle);
                activity.startActivity(i);
            }
        });
        page3Input.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(activity, WebPageActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url", "file:///android_asset/input.html");
                i.putExtras(bundle);
                activity.startActivity(i);
            }
        });
    }

    public MainSpringWebController initView(){
        loginButton = (Button)activity.findViewById(R.id.page4_login);
        homeLL = (LinearLayout)activity.findViewById(R.id.navigation_home_page);
        chooseLL = (LinearLayout)activity.findViewById(R.id.navigation_choose_page);
        heavyLL = (LinearLayout)activity.findViewById(R.id.navigation_heavy_page);
        meLL = (LinearLayout)activity.findViewById(R.id.navigation_me_page);

        page2Input = (RelativeLayout)activity.findViewById(R.id.page2_data_input);
        page2View = (RelativeLayout)activity.findViewById(R.id.page2_data_view);
        page2Manage = (RelativeLayout)activity.findViewById(R.id.page2_data_manage);
        page3Input = (RelativeLayout)activity.findViewById(R.id.page3_data_input);
        page3View = (RelativeLayout)activity.findViewById(R.id.page3_data_view);
        page3Manage = (RelativeLayout)activity.findViewById(R.id.page3_data_manage);
        registerEvent();
        return this;
    }

}
